package cn.tedu.mall.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.util.StringUtils;
//POJO:封装数据库表数据    VO:为了满足前端所返回数据的格式的对象为VO
public class ImageVO {
    private Integer error; //0代表上传正确  1代表上传失败
    private String url;//实现图片回显时所访问的路径
    private Integer width;//宽度
    private Integer height;//高度
    public ImageVO(){}

    public ImageVO(Integer error, String url, Integer width, Integer height) {
        this.error = error;
        this.url = url;
        this.width = width;
        this.height = height;
    }

    public Integer getError() {
        return error;
    }

    public void setError(Integer error) {
        this.error = error;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Integer getWidth() {
        return width;
    }

    public void setWidth(Integer width) {
        this.width = width;
    }

    public Integer getHeight() {
        return height;
    }

    public void setHeight(Integer height) {
        this.height = height;
    }

    @Override
    public String toString() {
        return "ImageVO{" +
                "error=" + error +
                ", url='" + url + '\'' +
                ", width=" + width +
                ", height=" + height +
                '}';
    }
    public static ImageVO fail(){
        return new ImageVO(1,null,null,null);
    }
    public static ImageVO success(String url,Integer width,Integer height){
        if (StringUtils.isEmpty(url) || width==null ||width<=0 || height==null ||height<=0){
            return ImageVO.fail();
        }
        return new ImageVO(0,url,width,height);
    }

}
